package com.glg.ioc;


import com.glg.ioc.component.UserComponent;
import com.glg.ioc.config.UserConfig;
import com.glg.ioc.controller.HelloController;
import com.glg.ioc.model.UserInfo;
import com.glg.ioc.repository.UserRepository;
import com.glg.ioc.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class IocApplication {

    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(IocApplication.class, args);
        /*//1. 根据类型获取 bean
        HelloController bean = context.getBean(HelloController.class);
        bean.sayHi();

        //2. 通过 bean 的名称去获取 bean
        //名字变成小驼峰了
        HelloController helloController = (HelloController) context.getBean("helloController");
        helloController.sayHi();

        //3. 根据名称和类型去获取 bean
        HelloController helloController1 = context.getBean("helloController", HelloController.class);
        helloController1.sayHi();*/

        /*UserService bean = context.getBean(UserService.class);
        bean.doService();
        UserComponent bean1 = context.getBean(UserComponent.class);
        bean1.doComponent();
        UserConfig bean2 = context.getBean(UserConfig.class);
        bean2.doConfig();
        UserRepository bean3 = context.getBean(UserRepository.class);
        bean3.doReponsitory();*/

        UserInfo bean = context.getBean(UserInfo.class);
        System.out.println(bean);
    }

}
